package com.sll.hosptials.utils;

import cn.hutool.jwt.JWTUtil;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.HashMap;

public class JwtUtil {
        /**
         * 密钥
         */
        private static final String secrt = "21laksdfiua42131giuwgelkwqjrlkjhadklsf";
        /**
         * 生成JWT的令牌
         * @return
         */
        public static String createJwtToken(String data){
            JwtBuilder builder = Jwts.builder()
                    .setSubject(data).signWith(SignatureAlgorithm.HS256,secrt);
            return builder.compact();
        }

        /**
         * 验签token的方法
         */
        public static String isToken(String jwtToken){
            try {
                Claims claim = Jwts.parser().setSigningKey(secrt)
                        .parseClaimsJws(jwtToken).getBody();
                return claim.getSubject();
            } catch (Exception e) {
                System.out.println("验签未通过！");
            }
            return null;
        }

}
